package cn.chinaunicom.sdsi.frm.workflow.traffic.pagger;

import net.sf.json.JSONObject;

import java.text.SimpleDateFormat;
import java.util.List;

/**
 * Created by adinlead on 17-7-13.
 */
public class Pagger {
    final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    public Pagger(int page, int linage, Long records, List rows) {
        this.page = page;
        this.linage = linage;
        this.records = records.intValue();
        this.rows = rows;
        total = (int) Math.ceil((double) records / (double) linage);
    }

    //    页码
    public int page;
//    行数
    public int linage;
//    总页码
    public int total;
//    记录总数
    public int records;
//    记录主体
    public List rows;

    public JSONObject toJSON(){
        JSONObject json = new JSONObject();
        json.put("page",this.page);
        json.put("linage",this.linage);
        json.put("total",this.total);
        json.put("records",this.records);
        json.put("rows",this.rows);
        return json;
    }

    public com.alibaba.fastjson.JSONObject toAliJSON(){
        com.alibaba.fastjson.JSONObject json = new com.alibaba.fastjson.JSONObject();
        json.put("page",this.page);
        json.put("linage",this.linage);
        json.put("total",this.total);
        json.put("records",this.records);
        json.put("rows",this.rows);
        return json;
    }

    public String toJSONString(){
        com.alibaba.fastjson.JSONObject json = new com.alibaba.fastjson.JSONObject();
        json.put("page",this.page);
        json.put("linage",this.linage);
        json.put("total",this.total);
        json.put("records",this.records);
        json.put("rows",this.rows);
        return json.toString();
    }
}
